#include<bits/stdc++.h>
using namespace std;
int p[100005],d[100005],v[3005],a[3005],b[10005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    for(int z=1;z<=t;z++){
        int n,m,L,V,box=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
                int q=m;
            if(a[i]>0){
                while(q!=0){
                    if(V<log(v[i]*v[i] + 2 * a * p[m-q+1])){
                        b[i]=p[m-q+1];
                        i++;
                    }
                    else{
                        q--;
                    }
                }
            }
            if(a[i]<0){
                q=m;
                b[i]=L+1;
                while(q!=0){
                    if(V<log(v[i]*v[i] + 2 * a * (p[m-q+1]))){
                        b[i]=b[m-q+1];
                        q--;
                    }
                }
            }
            if(a[i]==0){
                q=m;
                if(v[i]>V){
                    b[i]=p[m-q+1];
                }
                else{
                    b[i]=L+1;
                }
            }
            if(b[i]!=L+1)
                box++;
        }
        sort(b+1,b+n+1);
        int bo=0;
        for(int i=1;i<=n;i++){
            if(b[i]<b[i+1])
                bo++;
        }
        cout<<box<<" "<<bo;
    }
    return 0;
}
